#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int N = 2e5 + 10, M = 2 * N;
int e[M], ne[M], h[N], idx, id[M], sz[N];
int t;
bool st[N];
int maxnum = 1;
void add(int a, int b, int i)
{
	e[idx] = b, ne[idx] = h[a], id[idx] = i, h[a] = idx++;
}
void dfs(int u, int last, int num){
	st[u] = true;
	if (sz[u] == 1 && u != 1)
	{
		maxnum = max(num, maxnum);
		return;
	}
	for (int i = h[u]; i != -1; i = ne[i])
	{
		if (!st[e[i]])
		{
		if (id[i] < last) dfs(e[i], id[i], num + 1);
		else dfs(e[i], id[i], num);
		}
	}
}
int main()
{
	cin >> t;
	
	while (t--)
	{
		int n;
		cin >> n;
		memset(h, -1, sizeof h);
		memset(st, false, sizeof st);
		for (int i = 0; i < n - 1; i++)
		{
			int u, v;
			cin >> u >> v;
			add(u, v, i), add(v, u, i);
			sz[u] ++, sz[v] ++;
		}

		maxnum = 1;

		dfs(1, 2e6, 1);

		cout << maxnum << endl;
	}
	return 0;
}